import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-04-08
 * Time: 16:44
 */
public class Test02 {
    volatile int flag = 0;
    public static void main(String[] args) {
        //线程1
        Test02 test02 = new Test02();
        Thread t1 = new Thread() {
            @Override
            public void run() {
                while (test02.flag == 0) {

                }
                System.out.println("循环结束");
            }
        };
        t1.start();

        //线程2
        Thread t2 = new Thread() {
            @Override
            public void run() {
                    Scanner scan = new Scanner(System.in);
                    test02.flag = scan.nextInt();
            }
        };
        t2.start();
    }
}
